<?php require_once('../Connections/locale.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE abbinamenti SET descrizione_abbinamento=%s WHERE id_abbinamento=%s",
                       GetSQLValueString($_POST['descrizione_abbinamento'], "text"),
                       GetSQLValueString($_POST['id_abbinamento'], "int"));

  mysql_select_db($database_locale, $locale);
  $Result1 = mysql_query($updateSQL, $locale) or die(mysql_error());

  $updateGoTo = "elenco_abbinamenti.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

$colname_abbinamento = "1";
if (isset($_GET['id_abbinamento'])) {
  $colname_abbinamento = (get_magic_quotes_gpc()) ? $_GET['id_abbinamento'] : addslashes($_GET['id_abbinamento']);
}
mysql_select_db($database_locale, $locale);
$query_abbinamento = sprintf("SELECT * FROM abbinamenti WHERE id_abbinamento = %s", $colname_abbinamento);
$abbinamento = mysql_query($query_abbinamento, $locale) or die(mysql_error());
$row_abbinamento = mysql_fetch_assoc($abbinamento);
$totalRows_abbinamento = mysql_num_rows($abbinamento);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../style.css" rel="stylesheet" type="text/css">
</head>

<body>
<fieldset>
<legend>Modifica Abbinamento</legend>

<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
  <table align="left">
    <tr valign="baseline">
      <td nowrap align="right">Descrizione:</td>
      <td><input type="text" name="descrizione_abbinamento" value="<?php echo $row_abbinamento['descrizione_abbinamento']; ?>" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">&nbsp;</td>
      <td><input type="submit" value="Aggiorna Abbinamento"></td>
    </tr>
  </table>
  <input type="hidden" name="MM_update" value="form1">
  <input type="hidden" name="id_abbinamento" value="<?php echo $row_abbinamento['id_abbinamento']; ?>">
</form>
</fieldset>
<p><a href="elenco_abbinamenti.php">&lt;- Torna a Elenco Abbinamenti</a> </p>
</body>
</html>
<?php
mysql_free_result($abbinamento);
?>
